package com.example.mybatis.util;


import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

public class EncUtil {

    public static String getMd5(String var) throws NoSuchAlgorithmException {
        StringBuilder result = null;
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(var.getBytes(StandardCharsets.UTF_8));
            byte[]   digest = md5.digest();
            BigInteger bigInt = new BigInteger(1, digest);
            result = new StringBuilder(bigInt.toString(16));
            while(result.length()<32){
                result.insert(0, "0");
            }

        }catch (Exception ex){
            ex.printStackTrace();
        }
        assert result != null;
        return result.toString();
    }

    public static void main(String[] args) throws NoSuchAlgorithmException {
        System.out.println(getMd5("123"));
    }
}

